package cn.wolfcode.shop.controller;

import cn.wolfcode.shop.domain.PropertyValue;import cn.wolfcode.shop.service.IPropertyValueService;
import cn.wolfcode.vo.JSONResultVo;import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/propertyValue")
public class PropertyValueController {

    @Reference
    private IPropertyValueService valueService;

    /**
     * 查看属性值
     * @param propertyId
     * @param model
     * @return
     */
    @RequestMapping("/get/{propertyId}")
    public String propertyValuePage(@PathVariable("propertyId") Long propertyId, Model model){

        model.addAttribute("propertyValueList",valueService.queryByPropertyId(propertyId));

       return "property/property_value_list";
    }


    @RequestMapping("/save")
    @ResponseBody
    public JSONResultVo batchSaveOrUpdate(@RequestBody List<PropertyValue> propertyValueList){

        valueService.batchSaveOrUpdate(propertyValueList);
        return JSONResultVo.instance();
    }

    @RequestMapping("/delete/{id}")
    @ResponseBody
    public JSONResultVo delete(@PathVariable("id") Long propertyValueId){

        valueService.deleteByPVId(propertyValueId);
        return JSONResultVo.instance();
    }

}
